/*
 * Copyright Radosław Smogura, 2012. All rights reserved.
 *
 * The content of this file is confidential and it is intelectual property
 * of copyright owners.
 * 
 *
 * $URL: http://reprap-ide.googlecode.com/svn/trunk/RepRapIDE/RepRapProject/src/main/java/eu/softper/reprap/project/RepRapProjectTemplate.java $
 * $Id: RepRapProjectTemplate.java 3 2012-11-19 10:58:30Z mail@smogura.eu $
 * $Revision: 3 $
 */
package eu.softper.reprap.project;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import javax.swing.event.ChangeListener;
import org.netbeans.api.templates.TemplateRegistration;
import org.openide.WizardDescriptor;
import org.openide.WizardDescriptor.Panel;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.FileUtil;

/**
 *
 * @author rsmogura
 */
@TemplateRegistration(
        folder="Project/RepRap",
        displayName="#ProjectTemplate_Standard_Name",
        iconBase="eu/softper/reprap/project/images/reprap_logo.png",
        position=1000
)
public class RepRapProjectTemplate implements WizardDescriptor.InstantiatingIterator{
    private RepRapNewProjectPanel directoryPanel;
    private WizardDescriptor wd;
    private RepRapProjectConfig config;
    
    private List<WizardDescriptor.Panel> panels;
    int cuurentPosition;
    
    public RepRapProjectTemplate() {
    }

    @Override
    public Set instantiate() throws IOException {
        File f = new File(directoryPanel.getTargetDirectory());
        FileObject targetDir = FileUtil.createFolder(f);        
        RepRapProject.saveProjectConfig(config, targetDir);
        
        return Collections.singleton(targetDir);
    }

    @Override
    public void initialize(WizardDescriptor wd) {
        this.wd = wd;
        this.config = new RepRapProjectConfig();
        directoryPanel = new RepRapNewProjectPanel(wd, config);
        
        panels = new ArrayList<Panel>();
        panels.add(directoryPanel);
    }

    @Override
    public void uninitialize(WizardDescriptor wd) {
        this.wd = null;
        this.directoryPanel = null;
    }

    @Override
    public Panel current() {
        return directoryPanel;
    }

    @Override
    public String name() {
        return "New RepRap project";
    }

    @Override
    public boolean hasNext() {
        return false;
    }

    @Override
    public boolean hasPrevious() {
        return false;
    }

    @Override
    public void nextPanel() {
    }

    @Override
    public void previousPanel() {
    }

    @Override
    public void addChangeListener(ChangeListener cl) {
    }

    @Override
    public void removeChangeListener(ChangeListener cl) {
    }
    
}
